home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / news / inn1.000 / inn1.4sec-linux-src.tar / inn / lib / getmodaddr.c < prev    next >
C/C++ Source or Header  |  1993-01-29  |  2KB  |  71 lines

  1. /*  $Revision: 1.10 $
  2. **
  3. */
  4. #include <stdio.h>
  5. #include <sys/types.h>
  6. #include "configdata.h"
  7. #include "paths.h"
  8. #include "libinn.h"
  9. #include "clibrary.h"
  10. #include "macros.h"
  11.  
  12.  
  13. /*
  14. **  Read the moderators file, looking for a moderator.
  15. */
  16. char *
  17. GetModeratorAddress(group)
  18.     char        *group;
  19. {
  20.     static char        address[SMBUF];
  21.     register FILE    *F;
  22.     register char    *p;
  23.     char        *save;
  24.     char        buff[BUFSIZ];
  25.     char        name[SMBUF];
  26.  
  27.     (void)strcpy(name, group);
  28.     address[0] = '\0';
  29.     if ((F = fopen(_PATH_MODERATORS, "r")) != NULL) {
  30.     while (fgets(buff, sizeof buff, F) != NULL) {
  31.         /* Skip blank and comment lines. */
  32.         if ((p = strchr(buff, '\n')) != NULL)
  33.         *p = '\0';
  34.         if (buff[0] == '\0' || buff[0] == COMMENT_CHAR)
  35.         continue;
  36.  
  37.         /* Snip off the first word. */
  38.         if ((p = strchr(buff, ':')) == NULL)
  39.         /* Malformed line... */
  40.         continue;
  41.         *p++ = '\0';
  42.  
  43.         /* If it pattern-matches the newsgroup, the second field is a
  44.          * format for mailing, with periods changed to dashes. */
  45.         if (wildmat(name, buff)) {
  46.         for (save = p; ISWHITE(*save); save++)
  47.             continue;
  48.         for (p = name; *p; p++)
  49.             if (*p == '.')
  50.             *p = '-';
  51.         (void)sprintf(address, save, name);
  52.         break;
  53.         }
  54.     }
  55.  
  56.     (void)fclose(F);
  57.     if (address[0])
  58.         return address;
  59.     }
  60.  
  61.     /* If we don't have an address, see if the config file has a default. */
  62.     if ((save = GetConfigValue(_CONF_MODMAILER)) == NULL)
  63.     return NULL;
  64.  
  65.     for (p = name; *p; p++)
  66.     if (*p == '.')
  67.         *p = '-';
  68.     (void)sprintf(address, save, name);
  69.     return address;
  70. }
  71.